import {
  HANDLE_CHANGE_INPUT,
  CHANGE_LIST,
  HANDLE_ENTER,
  HANDLE_LEAVE,
  HANDLE_CHANGE_PAGE
} from './constants'
import {
  fromJS
} from 'immutable'
import Axios from 'axios'
export const searchFocus = () => ({
  type: HANDLE_CHANGE_INPUT
})
export const mouseEnter = () => ({
  type: HANDLE_ENTER
})
export const mouseLeave = () => ({
  type: HANDLE_LEAVE
})
export const changePage = () => ({
  type: HANDLE_CHANGE_PAGE
})
const changeList = (data = []) => ({
  type: CHANGE_LIST,
  data: fromJS(data),
  totalPage: Math.ceil(data.length / 10)
})
export const getList = () => {
  return dispatch => {
    Axios.get('/api/headerList.json').then(res => {
      if(res.data.success) {
        dispatch(changeList(res.data.data))
      }
    })
  }
}